package com.jiangjiang.eshop.auth.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiangjiang.eshop.auth.dao.RolePriorityRelationshipMapper;
import com.jiangjiang.eshop.auth.domain.RolePriorityRelationshipEntity;
import org.springframework.stereotype.Service;

/**
 * @ClassName RolePriorityRelationshipService
 * @Description TODO
 * @Author jhw
 * @Date 2021/5/8 11:29
 * @Version 1.0
 **/
@Service
public class RolePriorityRelationShipService extends ServiceImpl<RolePriorityRelationshipMapper, RolePriorityRelationshipEntity> {


    /**
     * 根据权限id查询角色与权限关联的数量
     * @param priorityId
     * @return
     */
    public Integer countByPriorityId(Long priorityId) {
        return this.count(
                Wrappers.<RolePriorityRelationshipEntity>lambdaQuery()
                        .eq(RolePriorityRelationshipEntity::getPriorityId, priorityId)
        );
    }

    /**
     * 根据角色id查询角色与权限关联的数量
     * @param roleId 角色id
     * @return
     */
    public void removeByRoleId(Long roleId) {
        LambdaQueryWrapper<RolePriorityRelationshipEntity> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(RolePriorityRelationshipEntity::getRoleId, roleId);
        this.getBaseMapper().delete(wrapper);
    }
}
